﻿using Infragistics.Win.UltraMessageBox;
using Infragistics.Win.UltraWinGrid;
using OrBitDataModule.Controls;
using OrBitDataModule.Dialog;
using OrBitDataModule;
using OrBitDataModule.Base;
using OrBitDataModule.Contract;
using OrBitDataModule.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using OrBitDataAcquisition.Common;
using System.Reflection;
using OrBitDataModule.Common;

namespace OrBitDataAcquisition
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();
            this.Load += MainForm_Load;
            this.FormClosed += MainForm_FormClosed;
            this.FormClosing += MainForm_FormClosing;
        }

        private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            taskManager?.Close();
        }

        private void MainForm_FormClosed(object sender, FormClosedEventArgs e)
        {
           Application.Exit();
        }
        RunningTaskManager taskManager = null;
        private void MainForm_Load(object sender, EventArgs e)
        {
            taskManager = new RunningTaskManager
            {
                Dock = DockStyle.Fill
            };
            this.ultraTabPageControl_task.Controls.Add(taskManager);
            TaskManager moduleManager = new TaskManager
            {
                Dock = DockStyle.Fill
            };
            ultraTabPageControl_module.Controls.Add(moduleManager);
            ScriptManager scriptManager = new ScriptManager
            {
                Dock = DockStyle.Fill
            };
            ultraTabPageControl_script.Controls.Add(scriptManager);

            this.cb_autoStartup.Checked = bool.Parse(ConfigHelper.GetValue("AutoStartup"));
            this.cb_autoStartup.CheckedChanged += Cb_autoStartup_CheckedChanged;
        }

        /// <summary>
        /// 设置开机启动
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Cb_autoStartup_CheckedChanged(object sender, EventArgs e)
        {
            StartupManager.SetStartup(Application.ProductName, Assembly.GetExecutingAssembly().Location, cb_autoStartup.Checked);
            ConfigHelper.SetValue("AutoStartup", cb_autoStartup.Checked.ToString());
        }
    }
}
